<?php
	include('Conexion.php');
	global $profesor;
	$profesor = $_COOKIE['id'];

	$con = mysql_connect($GLOBALS["server"],$GLOBALS["host"],$GLOBALS["pass"]) or die ('Ocurri&oacute; el siguiente error en la conexi&oacute;n: ' . mysql_error());
	mysql_select_db($GLOBALS["database"],$con);

if (isset($_POST['btn-submit'])) {
	$name = $_POST['field-name'];
	$lastName = $_POST['field-lastName'];
	$sex = $_POST['radio-sex'];
	$mail = $_POST['field-mail'];
	$pwd = $_POST['field-pwd'];
	$repwd = $_POST['field-repwd'];
	$entrar = true;
	
	if($name == "") $entrar = false; 
	if($lastName == "") $entrar = false; 
	if($mail == "") $entrar = false; 
	if($pwd == "") $entrar = false; 
	if($repwd == "") $entrar = false; 
	if($pwd != $repwd) $entrar = false; 
	
	if($entrar){
		mysql_query("UPDATE profesor  SET Profe_Nombre='".$name."', Profe_Apell='".$lastName."', Profe_Sexo='".$sex."', Profe_Email='".$mail."' ,Profe_Pass='".$pwd."' WHERE Profe_ID='".$profesor."'", $con) or die("MySQL Login Error: ".mysql_error());
		echo '<p>El perfil ha sido actualizado</p>';
	}
	mysql_close();
}
?>
<h1>Datos del usuario</h1>
<form id="form1" action="Home.php?page=perfil" method="get">
<div>
<?php
$resultado = mysql_query("SELECT Profe_Nombre,Profe_Apell,Profe_Sexo,Profe_Email,Profe_Pass FROM profesor WHERE Profe_ID='".$profesor."'", $con) or die("MySQL Login Error: ".mysql_error());
	
	$row = mysql_fetch_array($resultado);
	$name = $row["0"];
	$lastName = $row["1"];
	$sex = $row["2"];
	$mail = $row["3"];
	$pwd = $row["4"];
?>
<label for="field-name">Nombre(s):</label>
<input type="text" id="field-name" name="field-name" value="<?php echo $name ?>" class="form-input"/>
<span name="field-name-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-name'] == "") echo "Favor de ingresar Nombre." ?></span>
<br />
<label for="field-lastName">Apellido(s):</label>
<input type="text" id="field-lastName" name="field-lastName" value="<?php echo $lastName ?>"/>
<span name="field-lastName-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-lastName'] == "") echo "Favor de ingresar Apellido." ?></span>
<br />
<fieldset><legend>Sexo</legend>
<?php
	if($sex == "M"){
?>
<input type="radio" id="radio-sex" name="radio-sex" value="M" checked/> Hombre
<input type="radio" id="radio-sex" name="radio-sex" value="F"/> Mujer
<?php
	} else {
?>
<input type="radio" id="radio-sex" name="radio-sex" value="M"/> Hombre
<input type="radio" id="radio-sex" name="radio-sex" value="F"checked/> Mujer
<?php
	} 
?>
</fieldset>
<label for="field-mail">Correo Electr&oacute;nico:</label>
<input type="text" id="field-mail" name="field-mail" value="<?php echo $mail ?>"/>
<span name="field-mail-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-mail'] == "") echo "Favor de ingresar su correo." ?></span>
<br />
<label for="field-pwd">Contrase&ntilde;a:</label>
<input type="password" id="field-pwd" name="field-pwd" value="<?php echo $pwd ?>"/>
<span name="field-pwd-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-pwd'] == "") echo "Favor de ingresar su contrase&ntilde;a." ?></span>
<br />
<label for="field-pwd">Reescribir Contrase&ntilde;a:</label>
<input type="password" id="field-repwd" name="field-repwd" value="<?php echo $pwd ?>"/>
<span name="field-pwd-span"><?php if(isset($_POST['btn-submit']) and $_POST['field-pwd'] == "") echo "Favor de ingresar su contrase&ntilde;a." ?></span>
<br />
<input type="submit" id="btn-submit" name="btn-submit" value="Actualizar"/>
<div class="clear"></div>
</div>
</form>